package name.fordj;

import ca.odell.glazedlists.Filterator;
import ca.odell.glazedlists.impl.beans.BeanProperty;

import java.util.List;
import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: Jeremy
 * Date: Mar 7, 2008
 * Time: 11:13:25 PM
  */
public class BeanPropertyFilterator<T> implements Filterator<Object, T> {
    private List<BeanProperty<T>> beanProperties;
    private String[] properties;
    public BeanPropertyFilterator(Class<T> clazz, String... properties) {
        this.properties = properties;
        beanProperties = new ArrayList<BeanProperty<T>>(properties.length);
        for (String s : properties) {
            beanProperties.add(new BeanProperty<T>(clazz, s, true, false));
        }
    }
    public void getFilterValues(List<Object> baseList, T element) {
        for (BeanProperty<T> bp : beanProperties) {
             baseList.add(bp.get(element));
        }
    }

    public String[] getProperties() {
        return properties;
    }

    /* public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        BeanPropertyFilterator that = (BeanPropertyFilterator) o;

        if (!beanProperties.getPropertyName().equals(that.beanProperties.getPropertyName())) return false;

        return true;
    }*/

    /*public int hashCode() {
        return beanProperties.getPropertyName().hashCode();
    }*/
}
